package com.gg.fmallspringboot.service.impl;

import com.gg.fmallspringboot.entity.Category;
import com.gg.fmallspringboot.mapper.CategoryMapper;
import com.gg.fmallspringboot.model.Result;
import com.gg.fmallspringboot.service.CategoryService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    private CategoryMapper categoryMapper;

    public CategoryServiceImpl(CategoryMapper categoryMapper) {
        this.categoryMapper = categoryMapper;
    }

    @Override
    public Result<Category> queryCategoryVo() {
        List<Category> categorys = categoryMapper.selectAllCategories2(0);
        Result<Category> result ;
        if (categorys==null){
            result = new Result(1,"查询失败");
        }else {
            result = new Result(0,"查询成功",categorys);
        }
        return result;
    }

    @Override
    public Result<Category> selectCategoryByLevel(Integer level) {
        List<Category> categories = categoryMapper.selectCategoryByLevel(level);
        Result<Category> result ;
        if (categories==null){
            result = new Result(1,"查询失败");
        }else {
            result = new Result(0,"查询成功",categories);
        }
        return result;
    }

}
